<template>
  <div class="main" @click="infoxian">
    <van-cell
      v-if="cover === 0"
      :title="atcimg.title"
      :label="label"
    ></van-cell>
    <van-cell v-else-if="cover === 1" :title="atcimg.title" :label="label">
      <van-image width="100" height="100" :src="atcimg.cover?.images[0]" />
    </van-cell>

    <van-cell v-else :title="atcimg.title">
      <template #label>
        <!-- 图片 -->
        <van-image
          width="100"
          height="100"
          :src="itms"
          v-for="(itms, index) in atcimg.cover?.images"
          :key="index"
        />
        <!-- 详情 -->
        <p>{{ label }}</p>
      </template></van-cell
    >
  </div>
</template>

<script>
import dayjs from '@/utils/day'
export default {
  name: 'homeA',
  props: {
    atcimg: {
      type: Object,
      default: () => ({})
    }
  },
  computed: {
    cover() {
      return this.atcimg.cover?.type
    },
    label() {
      const { pubdate, comm_count, aut_name } = this.atcimg
      return `${aut_name}${comm_count}评论${dayjs(pubdate).fromNow()}`
    }
  },
  methods: {
    infoxian() {
      const a = this.atcimg.art_id
      const b = this.atcimg.aut_id
      this.$router.push({
        name: 'detail',
        params: { name: a, id: b }
      })
    }
  }
}
</script>

<style></style>
